<template>
  <div class="search_course_name">
    <el-select
      :value="studentId"
      filterable
      @change="selectName"
      placeholder="请输入学生关键词"
    
      :loading="loading"
    >
      <el-option
        v-for="item in studentList"
        :key="item.id"
        :label="item.studentName"
        :value="item.id"
      >
      </el-option>
    </el-select>
  </div>
</template>

<script>
import { getUserByName } from "@/api/school/student";
export default {
  data() {
    return {
      studentId: "",
      studentList: [],
      loading: false,
      open: false,
      refId: ''
    };
  },
  created() {
    this.init()
  },
  methods: {
    init(e) {
      this.studentId = e ? e : ''
      this.studentList = [];
      this.loading = false;
      this.open = false;
      this.refId = ''
      //if (e) this.refId = e
      this.getUserByName();
    },
    selectName(e) {
      // this.studentList.forEach(item => {
      //   if (item.id == e) {
      //     console.log(item)
      //     this.studentId = item.studentName
      //   }
      // })
      this.studentId = e;
      this.$emit("change", e);
    },
    setClassName(e) {
      this.$nextTick(() => {
        document.getElementById(this.refId).value = e ? e : ''
      })
    },
    getUserByName(query) {
      this.loading = true;
      getUserByName({ studentName: query }).then((res) => {
        console.log(res);
        this.loading = false;
        this.studentList = res.data;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.search_course_name {
  width: 100%;
  height: 100%;
}
</style>